<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
             label-position="left"
    >
      <el-form-item prop="wtaskCode">
        <el-input
          v-model="queryParams.wtaskCode"
          placeholder="请输入检验单编号/名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="reportPCode">
        <el-input
          v-model="queryParams.reportPCode"
          placeholder="请选择产品"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="reportQcPeo">
        <el-input
          v-model="queryParams.reportQcPeo"
          placeholder="请输入质检人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="reportOBatch">
        <el-input
          v-model="queryParams.reportOBatch"
          placeholder="请输入工单批次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="reportTime">
        <el-date-picker clearable
                        v-model="queryParams.reportTime"
                        type="datetime"
                        value-format="yyyy-MM-dd hh:mm:ss"
                        placeholder="请选择检验日期"
                        style="width: 205px !important;"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="reportResult">
        <el-select v-model="queryParams.reportResult" placeholder="请选择质检结果" clearable>
          <el-option
            v-for="dict in getQualityYesNo"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item style="width: calc(100% - 20px); text-align: right">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link :to="'/qc/pro-quality-change'" class="link-type">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            v-hasPermi="['qc:proQuality:add']"
          >新增
          </el-button>
        </router-link>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['qc:proQuality:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['qc:proQuality:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['qc:proQuality:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="proQualityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column label="序号" type="index" align="center" fixed />
      <el-table-column label="检验单名称" align="center" prop="reportQcName" width="120" fixed>
        <template slot-scope="scope">
          <span @click="toDetail(scope.row.reportQcCode)">
          {{ scope.row.reportQcName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="检验单编号" align="center" prop="reportQcCode" width="150" fixed />
      <el-table-column label="产品名称" align="center" prop="gbsGood.pdName" width="120" />
      <el-table-column label="产品编号" align="center" prop="gbsGood.pdCode" width="150" />
      <el-table-column label="规格型号" align="center" prop="gbsGood.pdSpecType" width="100" />
      <el-table-column label="单位" align="center" prop="gbsGood.gbsGoodUnit.guName" width="100" />
      <el-table-column label="产品类型" align="center" prop="gbsGood.gbsGoodClass.gcName" width="100" />
      <el-table-column label="批次号" align="center" prop="reportOBatch" width="100" />
      <el-table-column label="质检类型" align="center" prop="reportType" width="100">
        <template slot-scope="scope">
          <dict-tag :options="getQualityType" :value="scope.row.reportType" />
        </template>
      </el-table-column>
      <el-table-column label="质检时间" align="center" prop="reportTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="质检人" align="center" prop="reportQcPeoName" />
      <el-table-column label="质检数" align="center" prop="reportQcNum" />
      <el-table-column label="合格数" align="center" prop="reportGood" />
      <el-table-column label="质检结果" align="center" prop="reportResult" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="getQualityYesNo" :value="scope.row.reportResult" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="160">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['qc:proQuality:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['qc:proQuality:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { delProQuality, listProQuality } from '@/api/yyj/qc/proQuality'
import { parseTime } from '@/utils/ruoyi'

export default {
  name: 'ProQuality',
  dicts: ['qc_quality_type', 'qc_quality_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 过程检验表格数据
      proQualityList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportCompleteNum: null,
        reportPeoCode: null,
        reportQcCode: null,
        reportQcName: null,
        reportType: null,
        reportQc: '1',
        reportQcPeo: null,
        reportQcPeoName: null,
        reportOCode: null,
        reportOCodeName: null,
        reportOBatch: null,
        reportPCode: null,
        reportTCode: null,
        reportTCodeName: null,
        reportWCellName: null,
        reportRouteName: null,
        reportProcedureName: null,
        reportProcedure: null,
        reportGroupName: null,
        reportQcNum: null,
        reportGood: null,
        reportTime: null,
        reportResult: null,
        reportDevCode: null,
        reportDesc: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        reportCompleteNum: [
          { required: true, message: '报工数量不能为空', trigger: 'blur' }
        ],
        reportPeoCode: [
          { required: true, message: '报工人不能为空', trigger: 'blur' }
        ],
        reportQcCode: [
          { required: true, message: '检验单code不能为空', trigger: 'blur' }
        ],
        reportQcName: [
          { required: true, message: '质检单名称不能为空', trigger: 'blur' }
        ],
        reportDevCode: [
          { required: true, message: '报工设备不能为空', trigger: 'blur' }
        ],
        createBy: [
          { required: true, message: '创建人不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  computed: {
    getQualityType() {
      return this.dict.type.qc_quality_type
    },
    getQualityYesNo() {
      return this.dict.type.qc_quality_yes_no
    }
  },
  methods: {
    parseTime,
    toDetail(reportQcCode) {
      this.$router.push({
        path: `/qc/pro-quality-detail/${reportQcCode}`
      })
    },
    /** 查询过程检验列表 */
    async getList() {
      this.loading = true
      const res = await listProQuality(this.queryParams)
      this.proQualityList = res.rows
      this.total = res.total
      this.loading = false
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.reportCode)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const reportQcCode = row.reportQcCode || this.ids
      this.$router.push({
        path: `/qc/pro-quality-change/${reportQcCode}`
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const reportCodes = row.reportCode || this.ids
      this.$modal.confirm('是否确认删除过程检验编号为"' + reportCodes + '"的数据项？').then(function() {
        return delProQuality(reportCodes)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('qc/proQuality/export', {
        ...this.queryParams
      }, `proQuality_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
